<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改评论管理')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-comment-edit" th:object="${forumComment}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">父ID：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="pid" type="hidden" th:field="*{pid}" />
                        <input class="form-control" type="text" onclick="selectCommentTree()" id="treeName" readonly="true" th:field="*{parentName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">目标ID：</label>
                <div class="col-sm-8">
                    <input name="tid" th:field="*{tid}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">评论内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{content}">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">点赞数：</label>
                <div class="col-sm-8">
                    <input name="upVote" th:field="*{upVote}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">反对数：</label>
                <div class="col-sm-8">
                    <input name="downVote" th:field="*{downVote}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">QQ：</label>
                <div class="col-sm-8">
                    <input name="qq" th:field="*{qq}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">邮箱：</label>
                <div class="col-sm-8">
                    <input name="email" th:field="*{email}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_available_status')}">
                        <input type="radio" th:id="${'available_' + dict.dictCode}" name="available" th:value="${dict.dictValue}" th:field="*{available}">
                        <label th:for="${'available_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "forum/comment";
        $("#form-comment-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-comment-edit').serialize());
            }
        }

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
							var obj = this;
							var data = new FormData();
							data.append("file", files[0]);
							$.ajax({
								type: "post",
								url: ctx + "common/upload",
								data: data,
								cache: false,
								contentType: false,
								processData: false,
								dataType: 'json',
								success: function(result) {
									if (result.code == web_status.SUCCESS) {
										$('#' + obj.id).summernote('insertImage', result.url);
									} else {
										$.modal.alertError(result.msg);
									}
								},
								error: function(error) {
									$.modal.alertWarning("图片上传失败。");
								}
							});
						}
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });

        /*评论管理-新增-选择父部门树*/
        function selectCommentTree() {
            var options = {
                title: '评论管理选择',
                width: "380",
                url: prefix + "/selectCommentTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }
    </script>
</body>
</html>